local socket = require("socket")
package.path = package.path ..';../?.lua'
local Client = require('CSmsg/client')
local Game = {}
Game.managers = {}
function Game:start()
    local interval = 0.5
    local tStart = socket:gettime()
    local tNow = tStart
    while true do
        tNow = socket:gettime()
        if tNow - tStart > interval then
            tStart = tNow
            self:update()
        end
    end
end

function Game:connect(host, port, timeout)
    if self.client == nil then
        self.client = Client:New()
    end
    self.client:connect(host, port, timeout)
end

function Game:request(message, callBack)

    self.socket:send(message)
end

function Game:received()
    local recvt, sendt, status
    -- while true do
        recvt, sendt, status = socket.select({self.socket}, nil, 1)
        while #recvt > 0 do
            local response, receive_status = self.socket:receive()
            if receive_status ~= "closed" then
                if response then
                    recvt, sendt, status = socket.select({self.socket}, nil, 1)
                        local callBack ,tbparam = self:parse(response)
                        callBack(tbparam)
                    return
                end
            else
                break
            end
        end
end

function Game:update()
    print(">>>>>>>>update",socket:gettime())
end


Game:start()
